<template>
  <!-- 搜索工作栏 -->
  <ContentWrap ref="form">
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <!-- <el-form-item label="旧年级" prop="oldGrade">
        <el-select
          v-model="queryParams.oldGrade"
          placeholder="请选择旧年级"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.CMIS_GRADE_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="新年级" prop="newGrade">
        <el-select
          v-model="queryParams.newGrade"
          placeholder="请选择新年级"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.CMIS_GRADE_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="学籍号" prop="studentCode">
        <el-input
          v-model.tirm="queryParams.studentCode"
          placeholder="请输入学籍号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="学生名称" prop="studentName">
        <el-input
          v-model.tirm="queryParams.studentName"
          placeholder="请输入学生名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="升学类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择升学类型"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.CMIS_CONTINUE_STUDY_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label-width="auto" label="旧在校状态" prop="oldState">
        <el-select
          v-model="queryParams.oldState"
          placeholder="请选择旧在校状态"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.CMIS_STUDENT_STATE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label-width="auto" label="新在校状态" prop="newState">
        <el-select
          v-model="queryParams.newState"
          placeholder="请选择新在校状态"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.CMIS_STUDENT_STATE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
        <!-- <el-button
          type="primary"
          plain
          @click="openForm('create')"
          v-hasPermi="['cmis:continue-study-record:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 新增
        </el-button> -->
        <el-button
          type="warning"
          plain
          @click="oneKeyStudentContinueStudyRecordForm"
          v-hasPermi="['cmis:continue-study-record:create']"
        >
          <Icon icon="ep:upload" class="mr-5px" /> 一键升学
        </el-button>
        <el-button
          type="primary"
          plain
          @click="openStudentContinueStudyRecordForm"
          v-hasPermi="['cmis:continue-study-record:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 升学
        </el-button>
        <el-button
          type="success"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['cmis:continue-study-record:export']"
        >
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap :setPadding="false">
    <el-table v-loading="loading" :data="list" stripe :max-height="tableHeight"
      >>
      <!-- <el-table-column label="id" prop="id" /> -->
      <el-table-column label="旧年级" prop="oldGrade">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CMIS_GRADE_TYPE" :value="scope.row.oldGrade" />
        </template>
      </el-table-column>
      <el-table-column label="新年级" prop="newGrade">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CMIS_GRADE_TYPE" :value="scope.row.newGrade" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="学生id" prop="studentId" /> -->
      <el-table-column label="学籍号" prop="studentCode" show-overflow-tooltip />
      <!-- <el-table-column label="部门id" prop="deptId" /> -->
      <!-- <el-table-column label="备注" prop="remark" /> -->
      <el-table-column label="学生名称" prop="studentName" show-overflow-tooltip />
      <el-table-column label="升学类型" prop="type">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CMIS_CONTINUE_STUDY_TYPE" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="旧在校状态" prop="oldState">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CMIS_STUDENT_STATE" :value="scope.row.oldState" />
        </template>
      </el-table-column>
      <el-table-column label="新在校状态" prop="newState">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CMIS_STUDENT_STATE" :value="scope.row.newState" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" fixed="right" width="100">
        <template #default>
          <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
            v-hasPermi="['cmis:continue-study-record:update']"
          >
            编辑
          </el-button>
          <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['cmis:continue-study-record:delete']"
          >
            删除
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <!-- <ContinueStudyRecordForm ref="formRef" @success="getList" /> -->
  <StudentContinueStudyRecordForm ref="ContinueStudyFormRef" @success="getList" />
</template>

<script setup lang="ts" name="ContinueStudyRecord">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import download from '@/utils/download'
import * as ContinueStudyRecordApi from '@/api/cmis/continueStudyRecord'
// import ContinueStudyRecordForm from './ContinueStudyRecordForm.vue'
import StudentContinueStudyRecordForm from './StudentContinueStudyRecordForm.vue'
const message = useMessage() // 消息弹窗
// const { t } = useI18n() // 国际化
const form = ref(null)
const { width, height } = useElementSize(form)
const tableHeight = useWindowSize(78 + 76, height)
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  createTime: [],
  oldGrade: null,
  newGrade: null,
  studentId: null,
  studentCode: null,
  deptId: null,
  remark: null,
  studentName: null,
  type: null,
  oldState: null,
  newState: null
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ContinueStudyRecordApi.getContinueStudyRecordPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
// const formRef = ref()
// const openForm = (type: string, id?: number) => {
//   formRef.value.open(type, id)
// }

//升学
const ContinueStudyFormRef = ref()
const openStudentContinueStudyRecordForm = () => {
  ContinueStudyFormRef.value.open(false, '升学')
}

//一键升学
const oneKeyStudentContinueStudyRecordForm = () => {
  ContinueStudyFormRef.value.open(true, '一键升学')
}

/** 删除按钮操作 */
// const handleDelete = async (id: number) => {
//   try {
//     // 删除的二次确认
//     await message.delConfirm()
//     // 发起删除
//     await ContinueStudyRecordApi.deleteContinueStudyRecord({ id })
//     message.success(t('common.delSuccess'))
//     // 刷新列表
//     await getList()
//   } catch {}
// }

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await ContinueStudyRecordApi.exportContinueStudyRecord(queryParams)
    download.excel(data, '升学记录.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
